//import java.util.Scanner;
//
//public class Main {
//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        long n = scanner.nextLong();
//        long sum = 0;
//        long a = 1, b = 1, c = 2;
//        for (long i = 4; i <= n; i += 3) {
//            a = c + b;
//            b = a + c;
//            c = b + a;
//        }
//        if (n % 3 == 0) sum = c;
//        else if (n % 3 == 1) sum = a;
//        else if (n % 3 == 2) sum = b;
//        System.out.println(sum);
//    }
//}

//1 3 5 7 9 11
//1 2 4 8

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.nextLine();
        String s2 = scanner.nextLine();
        int n = s1.length(), m = s2.length();
        //将大小字母转成小写
        StringBuffer str1 = new StringBuffer(" ");
        StringBuffer str2 = new StringBuffer(" ");
        for(char ch:s1.toCharArray()) {
            if(ch >= 'A' && ch <= 'Z') str1.append((char)(ch + 'a' - 'A'));
            else str1.append(ch);
        }
        for(char ch:s2.toCharArray()) {
            if(ch >= 'A' && ch <= 'Z') str2.append((char)(ch + 'a' - 'A'));
            else str2.append(ch);
        }

        boolean[][] dp = new boolean[n + 1][m + 1];
        dp[0][0] = true;
        for (int i = 1; i <= n; i++) {
            if (str1.charAt(i) == '*') dp[0][i] = true;
            else break;
        }

        for (int i = 1; i <= n; i++) {
            char ch1 = str1.charAt(i);
            for (int j = 1; j <= m; j++) {
                char ch2 = str2.charAt(j);
                if (ch1 == ch2 && dp[i - 1][j - 1]) dp[i][j] = dp[i-1][j-1];
                else if(ch1 == '?' &&
                        ((ch2 >= '0' && ch2 <= '9') ||
                                (ch2 >= 'a' && ch2 <= 'z'))) dp[i][j] = dp[i-1][j-1];
                else if(ch1 == '*') dp[i][j] = dp[i][j-1] || dp[i-1][j];
            }
        }

        System.out.println(dp[n][m]);
    }
}